<cfparam name="show_debug" default="0">

<cfparam name="page_name" default="Daily Recap">
<cfparam name="row_header" default="##4F81BD">
<cfparam name="row_colors" default="##D0D8E8,##E9EDF4">
<cfparam name="date_to_view" default="#Now()#">

<!--- This is the math total sections for top left table--->
<cfparam name="payment_type_cash" default="0">
<cfparam name="payment_type_credit" default="0">
<cfparam name="payment_type_check" default="0">
<cfparam name="payment_type_giftcard" default="0">
<cfparam name="payment_type_voids" default="0">
<cfparam name="payment_type_total" default="0">

<!--- This is the math total sections for top right table--->
<cfparam name="cash_in" default="0">
<cfparam name="cash_sales" default="0">
<cfparam name="cash_change" default="0">
<cfparam name="cash_total" default="0">

<!--- This is the math total sections for bottom table--->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title><cfoutput>#page_name#</cfoutput></title>
	<link rel="stylesheet" href="http://code.jquery.com/ui/1.8.18/themes/base/jquery-ui.css" type="text/css" media="all" />
	<link rel="stylesheet" href="http://static.jquery.com/ui/css/demo-docs-theme/ui.theme.css" type="text/css" media="all" />
	<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
	<script src="http://code.jquery.com/ui/1.8.18/jquery-ui.min.js" type="text/javascript"></script>
	<style type="text/css">
	<!--
	body,td,th {
		font-family: Verdana, Arial, Helvetica, sans-serif;
		font-size: 12px;
	}
	body {
		margin-left: 0px;
		margin-top: 0px;
		margin-right: 0px;
		margin-bottom: 0px;
	}
	.style1 {font-size: 18px}
	.style2 {font-size: 9px}
	-->
	</style>
</head>

<cfquery datasource="#dsn1#" name="daily_recap">
	SELECT * FROM tblpayments
	WHERE REPORTDATE like '#DateFormat(date_to_view,"mm/dd/yyyy")#'
</cfquery>

<cfloop query="daily_recap">
	<cfif IsNumeric(cash)>
		<cfset payment_type_cash = payment_type_cash+CASH>
		<cfset payment_type_total = payment_type_total+CASH>
	</cfif>
	<cfif IsNumeric(credit)>
		<cfset payment_type_credit = payment_type_credit+CREDIT>
		<cfset payment_type_total = payment_type_total+CREDIT>
	</cfif>
	<cfif IsNumeric(check)>
		<cfset payment_type_check = payment_type_credit+CHECK>
		<cfset payment_type_total = payment_type_total+CHECK>
	</cfif>
	<cfif IsNumeric(giftcard)>
		<cfset payment_type_giftcard = payment_type_credit+GIFTCARD>
		<cfset payment_type_total = payment_type_total+GIFTCARD>
	</cfif>
	
	<cfif PAYMENTTYPE IS "CASH" AND IsNumeric(AMOUNTPAID)>
		<cfset cash_in = cash_in+AMOUNTPAID>
	</cfif>
	<cfif IsNumeric(change)>
		<cfset cash_change = cash_change+change>
	</cfif>
</cfloop>

<!--- Now that all the math is done get totals --->
<cfset cash_total = cash_in+cash_sales-cash_change>

	<body>
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td colspan="3"><span class="style1"><cfoutput>#ucase(page_name)#</cfoutput>
<script>
	$(function() {
		$( "#datepicker" ).datepicker();
	});
</script>
	<input type="text" id="datepicker" value="<cfoutput>#DateFormat(date_to_view,"mm/dd/yyyy")#</cfoutput>" onchange='window.location.href="http://<cfoutput>#cgi.SERVER_NAME##CGI.SCRIPT_NAME#</cfoutput>?date_to_view=" + this.value'></span><br><br></td>
			</tr>
			<tr>
				<td width="50%" valign="top">
					<table width="100%" border="0" cellpadding="4">
						<tr bgcolor="<cfoutput>#row_header#</cfoutput>">
							<td><font style="color:#FFFFFF;font-size:12pt;font-weight: bold;">Payment Type Totals</font></td>
							<td><font style="color:#FFFFFF;font-size:12pt;font-weight: bold;">Amount</font></td>
						</tr>
						<tr bgcolor="<cfoutput>#ListGetAt(row_colors,1)#</cfoutput>">
							<td><font style="font-size:12pt;font-weight: bold;">Cash</font></td>
							<td><font style="font-size:12pt;font-weight: bold;"><cfoutput>#DollarFormat(payment_type_cash)#</cfoutput></font></td>
						</tr>
						<tr bgcolor="<cfoutput>#ListGetAt(row_colors,2)#</cfoutput>">
							<td><font style="font-size:12pt;font-weight: bold;">Credit</font></td>
							<td><font style="font-size:12pt;font-weight: bold;"><cfoutput>#DollarFormat(payment_type_credit)#</cfoutput></font></td>
						</tr>
						<tr bgcolor="<cfoutput>#ListGetAt(row_colors,1)#</cfoutput>">
							<td><font style="font-size:12pt;font-weight: bold;">Check</font></td>
							<td><font style="font-size:12pt;font-weight: bold;"><cfoutput>#DollarFormat(payment_type_check)#</cfoutput></font></td>
						</tr>
						<tr bgcolor="<cfoutput>#ListGetAt(row_colors,2)#</cfoutput>">
							<td><font style="font-size:12pt;font-weight: bold;">Gift Card</font></td>
							<td><font style="font-size:12pt;font-weight: bold;"><cfoutput>#DollarFormat(payment_type_giftcard)#</cfoutput></font></td>
						</tr>
						<tr bgcolor="<cfoutput>#ListGetAt(row_colors,1)#</cfoutput>">
							<td><font style="font-size:12pt;font-weight: bold;">Voids</font></td>
							<td><font style="font-size:12pt;font-weight: bold;"><cfoutput>#DollarFormat(payment_type_voids)#</cfoutput></font></td>
						</tr>
						<tr bgcolor="<cfoutput>#ListGetAt(row_colors,2)#</cfoutput>">
							<td><font style="font-size:12pt;font-weight: bold;">Total Amount</font></td>
							<td><font style="font-size:12pt;font-weight: bold;"><cfoutput>#DollarFormat(payment_type_total)#</cfoutput></font></td>
						</tr>
					</table>
				</td>
				<td bgcolor="#FFFFFF">&nbsp;</td>
				<td width="50%" valign="top">
					<table width="100%" border="0" cellpadding="4">
						<tr bgcolor="<cfoutput>#row_header#</cfoutput>">
							<td><font style="color:#FFFFFF;font-size:12pt;font-weight: bold;">Cash</font></td>
							<td><font style="color:#FFFFFF;font-size:12pt;font-weight: bold;">Amount</font></td>
						</tr>
						<tr bgcolor="<cfoutput>#ListGetAt(row_colors,1)#</cfoutput>">
							<td><font style="font-size:12pt;font-weight: bold;">Cash In</font></td>
							<td><font style="font-size:12pt;font-weight: bold;"><cfoutput>#DollarFormat(cash_in)#</cfoutput></font></td>
						</tr>
						<tr bgcolor="<cfoutput>#ListGetAt(row_colors,2)#</cfoutput>">
							<td><font style="font-size:12pt;font-weight: bold;">Cash Sales</font></td>
							<td><font style="font-size:12pt;font-weight: bold;"><cfoutput>#DollarFormat(cash_sales)#</cfoutput></font></td>
						</tr>
						<tr bgcolor="<cfoutput>#ListGetAt(row_colors,1)#</cfoutput>">
							<td><font style="font-size:12pt;font-weight: bold;">Change</font></td>
							<td><font style="font-size:12pt;font-weight: bold;"><cfoutput>#DollarFormat(cash_change)#</cfoutput></font></td>
						</tr>
						<tr bgcolor="<cfoutput>#ListGetAt(row_colors,2)#</cfoutput>">
							<td><font style="font-size:12pt;font-weight: bold;">&nbsp;</font></td>
							<td><font style="font-size:12pt;font-weight: bold;"></font></td>
						</tr>
						<tr bgcolor="<cfoutput>#ListGetAt(row_colors,1)#</cfoutput>">
							<td><font style="font-size:12pt;font-weight: bold;">&nbsp;</font></td>
							<td><font style="font-size:12pt;font-weight: bold;"></font></td>
						</tr>
						<tr bgcolor="<cfoutput>#ListGetAt(row_colors,2)#</cfoutput>">
							<td><font style="font-size:12pt;font-weight: bold;">Total Cash on Hand</font></td>
							<td><font style="font-size:12pt;font-weight: bold;"><cfoutput>#DollarFormat(cash_total)#</cfoutput></font></td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
		
		<cftry>
		<br><br>
		<!--- Go query terminals for that day --->
		<cfquery datasource="#dsn1#" name="daily_recap_terminals">
			SELECT TERMINAL as TERMINAL_name 
			FROM tblpayments
			WHERE REPORTDATE like '#DateFormat(date_to_view,"mm/dd/yyyy")#'
			GROUP BY TERMINAL
		</cfquery>
		
		<table width="100%" border="0" cellpadding="4">
			<tr bgcolor="<cfoutput>#row_header#</cfoutput>">
				<td><font style="color:#FFFFFF;font-size:8pt;font-weight: bold;">Terminal</font></td>
				<td><font style="color:#FFFFFF;font-size:8pt;font-weight: bold;">Payment ID</font></td>
				<td><font style="color:#FFFFFF;font-size:8pt;font-weight: bold;">Receipt Num</font></td>
				<td><font style="color:#FFFFFF;font-size:8pt;font-weight: bold;">TransType</font></td>
				<td><font style="color:#FFFFFF;font-size:8pt;font-weight: bold;">Cash</font></td>
				<td><font style="color:#FFFFFF;font-size:8pt;font-weight: bold;">Credit</font></td>
				<td><font style="color:#FFFFFF;font-size:8pt;font-weight: bold;">Check</font></td>
				<td><font style="color:#FFFFFF;font-size:8pt;font-weight: bold;">Giftcard</font></td>
				<td><font style="color:#FFFFFF;font-size:8pt;font-weight: bold;">Change</font></td>
				<td><font style="color:#FFFFFF;font-size:8pt;font-weight: bold;">Total</font></td>
			</tr>
			<cfset last_row_color = 2>
			<cfoutput query="daily_recap_terminals">
				<!--- Go query specfic terminal for that day --->
				<cfquery datasource="#dsn1#" name="daily_recap_this_terminal">
					SELECT * 
					FROM tblpayments
					WHERE REPORTDATE like '#DateFormat(date_to_view,"mm/dd/yyyy")#'
					<cfif Len(trim(TERMINAL_NAME)) GT 1>
						AND TERMINAL = '#TERMINAL_NAME#'
					</cfif>
					ORDER BY RECEIPTNUM
				</cfquery>
				<cfif Len(trim(TERMINAL_NAME)) GT 1>
					<cfif last_row_color IS 2>
						<cfset this_row_color = 1>
					<cfelse>
						<cfset this_row_color = 2>
					</cfif>
					<tr bgcolor="#ListGetAt(row_colors,this_row_color)#">
						<td width="10%"><font style="font-size:8pt;font-weight: bold;">#TERMINAL_NAME#</font></td>
						<td width="10%"><font style="font-size:8pt;font-weight: bold;"></font></td>
						<td width="10%"><font style="font-size:8pt;font-weight: bold;"></font></td>
						<td width="10%"><font style="font-size:8pt;font-weight: bold;"></font></td>
						<td width="10%"><font style="font-size:8pt;font-weight: bold;"></font></td>
						<td width="10%"><font style="font-size:8pt;font-weight: bold;"></font></td>
						<td width="10%"><font style="font-size:8pt;font-weight: bold;"></font></td>
						<td width="10%"><font style="font-size:8pt;font-weight: bold;"></font></td>
						<td width="10%"><font style="font-size:8pt;font-weight: bold;"></font></td>
						<td width="10%"><font style="font-size:8pt;font-weight: bold;"></font></td>
					</tr>
					<cfset last_row_color = this_row_color>
				</cfif>
			</cfoutput>

			<cfset grand_total = 0>
			<cfif IsDefined('daily_recap_this_terminal')>
				<!--- This is the Grand total for the whol bottom row--->
				<cfoutput query="daily_recap_this_terminal">
					<cfif last_row_color IS 2>
						<cfset this_row_color = 1>
					<cfelse>
						<cfset this_row_color = 2>
					</cfif>
					<!--- Set all values to zero so we can do math --->
					<cfset this_cash = 0>
					<cfset this_credit = 0>
					<cfset this_check = 0>
					<cfset this_giftcard = 0>
					<cfset this_change = 0>
					<cfset this_total = 0>
					
					<!--- Check if its a number and if so do math now --->
					<cfif IsNumeric(CASH)>
						<cfset this_cash = CASH>
						<cfset this_total = this_total+CASH>
					</cfif>
					<cfif IsNumeric(CREDIT)>
						<cfset this_credit = CREDIT>
						<cfset this_total = this_total+CREDIT>
					</cfif>
					<cfif IsNumeric(CHECK)>
						<cfset this_check = CHECK>
						<cfset this_total = this_total+CHECK>
					</cfif>
					<!--- TO DO: FIGURE out GIFTCARD COLUMN--->
					<cfif IsNumeric(CHANGE)>
						<cfset this_change = CHANGE>
						<cfset this_total = this_total-CHANGE>
						<cfset grand_total = grand_total+this_total>
					</cfif>
					
					<tr bgcolor="#ListGetAt(row_colors,this_row_color)#">
						<td><font style="font-size:8pt;font-weight: bold;">&nbsp;</font></td>
						<td><font style="font-size:8pt;font-weight: bold;">#PAYMENTID#</font></td>
						<td><font style="font-size:8pt;font-weight: bold;">#RECEIPTNUM#</font></td>
						<td><font style="font-size:8pt;font-weight: bold;">#TRANSTYPE#</font></td>
						<td><font style="font-size:8pt;font-weight: bold;">#DollarFormat(THIS_CASH)#</font></td>
						<td><font style="font-size:8pt;font-weight: bold;">#DollarFormat(THIS_CREDIT)#</font></td>
						<td><font style="font-size:8pt;font-weight: bold;">#DollarFormat(THIS_CHECK)#</font></td>
						<td><font style="font-size:8pt;font-weight: bold;">#DollarFormat(THIS_GIFTCARD)#</font></td>
						<td><font style="font-size:8pt;font-weight: bold;">#DollarFormat(THIS_CHANGE)#</font></td>
						<td><font style="font-size:8pt;font-weight: bold;">#DollarFormat(THIS_TOTAL)#</font></td>
					</tr>
					<cfset last_row_color = this_row_color>
				</cfoutput>
		</cfif>
				<cfif last_row_color IS 2>
					<cfset this_row_color = 1>
				<cfelse>
					<cfset this_row_color = 2>
				</cfif>
					<tr bgcolor="<cfoutput>#ListGetAt(row_colors,this_row_color)#</cfoutput>">
						<td><font style="font-size:8pt;font-weight: bold;">&nbsp;</font></td>
						<td><font style="font-size:8pt;font-weight: bold;"></font></td>
						<td><font style="font-size:8pt;font-weight: bold;"></font></td>
						<td><font style="font-size:8pt;font-weight: bold;"></font></td>
						<td><font style="font-size:8pt;font-weight: bold;"></font></td>
						<td><font style="font-size:8pt;font-weight: bold;"></font></td>
						<td><font style="font-size:8pt;font-weight: bold;"></font></td>
						<td><font style="font-size:8pt;font-weight: bold;"></font></td>
						<td align="right"><font style="font-size:8pt;font-weight: bold;">Total Amount</font></td>
						<td><font style="font-size:8pt;font-weight: bold;"><cfoutput>#DollarFormat(grand_total)#</cfoutput></font></td>
					</tr>
			</table>
	</body>
</html>
<cfcatch type="ANY">
</cfcatch>
</cftry>